package htmlWriter;

import edu.mta.pokerstats.Player;
import edu.mta.pokerstats.Team;

/**
 *
 * @author owner
 */
public class HtmlWriter {
    
    public String LogInPage()
    {
       String returnHtml = new String();
        returnHtml ="<div id='DivLogInSignUp'><div id='DivLogin' class='LogInSignUp'>"+
							"<form action='registration' method='post' id='FormLogin'>"+
							"<label>Username:</label><br/>"+
							"<input type='text' name='playerUsername' placeholder='Enter username...' id='TextPlayerUsername'/><span id='ErrorPlayerUsername' class='ErrorNoDisplay'><img src='res/img/error.png'/></span><br/>"+
							"<label>Password:</label><br/>"+
							"<input type='password' placeholder='Enter password...' id='TextPlayerPassword'/><span id='ErrorPlayerPassword' class='ErrorNoDisplay'><img src='res/img/error.png'/></span><br/>"+
							"<input type='hidden' name='action' value='LogIn'/>"+
						"</form>"+
						"<button class='ButtonLogInSignUp' onClick='checkLogInValidation()'>LogIn</button><br/>" +
						"<span id='LogInError' class='ErrorNoDisplay'></span>"+
					"</div>"+
					"<div id='DivSignup' class='LogInSignUp signUpEmpty'>"+
						"<label>Click here to Sign Up!</label> <br/>"+
						"<button class='ButtonLogInSignUp' onClick='showSignUpFields()'>SignUp</button>"+
					"</div></div>";
        return returnHtml;
    }
    
    public String HoldemGeneral()
    {
        String returnHtml = new String();
        returnHtml = "<div class='Heading'>"
                + "<h2>Texas Hold'em : General Information</h2>"
                + "</div>"
                + "<div id='content'>"
                    + "<p>In Texas hold 'em, as in all variants of poker, individuals "
                    + "compete for an amount of money or chips contributed by the players "
                    + "themselves (called the pot). Because the cards are dealt randomly "
                    + "and outside the control of the players, each player attempts to "
                    + "control the amount of money in the pot based either on the hand they "
                    + "are holding, or on their prediction as to what their opponents may "
                    + "be holding.</p>"
                    + "<p>The game is divided into a series of hands or deals; at the "
                    + "conclusion of each hand, the pot is typically awarded to one player "
                    + "(an exception in which the pot is divided between more than one is "
                    + "discussed below). A hand may end at the showdown, in which case the "
                    + "remaining players compare their hands and the highest hand is "
                    + "awarded the pot; that highest hand is usually held by only one "
                    + "player, but can be held by more in the case of a tie. The other "
                    + "possibility for the conclusion of a hand occurs when all but one "
                    + "player has folded and have thereby abandoned any claim to the pot, "
                    + "in which case the pot is awarded to the player who has not folded."
                    + "</p>"
                    + "<p>The objective of winning players is not to win every "
                    + "individual hand, but rather to make mathematically and "
                    + "psychologically correct decisions regarding when and how much to "
                    + "bet, raise, call or fold. By making such decisions, winning poker "
                    + "players can maximize their expected gain on each round of betting, "
                    + "thereby increasing their long-term winnings.</p>"
                + "</div>";
        return returnHtml;
    }
    
    public String HoldemRules()
    {
        String returnHtml = new String();
        returnHtml ="<div id='rules'>"
                + "<div class='Heading'>"
                    + "<h2>Texas Hold'em : Rules of the game</h2>"
                + "</div>"
                + "<dl>"
                    + "<dt>"
                        + "<a href='#bettingSection'>Betting Structures</a>"
                    + "</dt>"
                        + "<dd id='bettingSection' class='largeSise'>"
                            + "<p>Hold 'em is normally played using small and big blind bets – "
                                + "forced bets by two players. Antes (forced contributions by all "
                                + "players) may be used in addition to blinds, particularly in later "
                                + "stages of tournament play. A dealer button is used to represent "
                                + "the player in the dealer position; the dealer button rotates "
                                + "clockwise after each hand, changing the position of the dealer and "
                                + "blinds. The small blind is posted by the player to the left of the "
                                + "dealer and is usually equal to half of the big blind. The big "
                                + "blind, posted by the player to the left of the small blind, is "
                                + "equal to the minimum bet. In tournament poker, the blind/ante "
                                + "structure periodically increases as the tournament progresses.</p>"
                            + "<p>When only two players remain, special 'head-to-head' or "
                                + "'heads up' rules are enforced and the blinds are posted "
                                + "differently. In this case, the person with the dealer button posts "
                                + "the small blind, while his/her opponent places the big blind. The "
                                + "dealer acts first before the flop. After the flop, the dealer acts "
                                + "last and continues to do so for the remainder of the hand.</p>"
                            + "<p>In no-limit hold 'em, players may bet or raise any amount "
                                + "over the minimum raise up to all of the chips the player has at "
                                + "the table (called an all-in bet). The minimum raise is equal to "
                                + "the size of the previous bet or raise. If someone wishes to "
                                + "re-raise, they must raise at least the amount of the previous "
                                + "raise. For example, if the big blind is $2 and there is a raise of "
                                + "$6 to a total of $8, a re-raise must be at least $6 more for a "
                                + "total of $14. If a raise or re-raise is all-in and does not equal "
                                + "the size of the previous raise, the initial raiser cannot re-raise "
                                + "again. This only matters of course if there were a call before the "
                                + "re-raise.</p>"
                        + "</dd>"
                    + "<dt>"
                        + "<a href='#playSection'>Play of the hand</a>"
                    + "</dt>"
                        + "<dd id='playSection' class='XlargeSize'>"
                            + "<p>Play begins with each player being dealt two cards face "
                                + "down, with the player in the small blind receiving the first card "
                                + "and the player in the button seat receiving the last card dealt. "
                                + "(As in most poker games, the deck is a standard 52-card deck "
                                + "containing no jokers.) These cards are the player's hole or pocket "
                                + "cards. These are the only cards each player will receive "
                                + "individually, and they will only (possibly) be revealed at the "
                                + "showdown, making Texas hold 'em a closed poker game.</p>"
                            + "<p>The hand begins with a 'pre-flop' betting round, beginning "
                                + "with the player to the left of the big blind (or the player to the "
                                + "left of the dealer, if no blinds are used) and continuing "
                                + "clockwise. A round of betting continues until every player has "
                                + "folded, put in all of their chips, or matched the amount put in by "
                                + "all other active players. See betting for a detailed account. Note "
                                + "that the blinds are considered 'live' in the pre-flop betting "
                                + "round, meaning that they are counted toward the amount that the "
                                + "blind player must contribute. If all players call around to the "
                                + "player in the big blind position, that player may either check or "
                                + "raise.</p>"
                            + "<p>After the pre-flop betting round, assuming there remain at "
                                + "least two players taking part in the hand, the dealer deals a "
                                + "flop, three face-up community cards. The flop is followed by a "
                                + "second betting round. This and all subsequent betting rounds begin "
                                + "with the player to the dealer's left and continue clockwise.</p>"
                            + "<p>After the flop betting round ends, a single community card "
                                + "(called the turn or fourth street) is dealt, followed by a third "
                                + "betting round. A final single community card (called the river or "
                                + "fifth street) is then dealt, followed by a fourth betting round "
                                + "and the showdown, if necessary.</p>"
                            + "<p>In all casinos, the dealer will burn a card before the flop, "
                                + "turn, and river. Because of this burn, players who are betting "
                                + "cannot see the back of the next community card to come. This is "
                                + "done for historical/traditional reasons, to avoid any possibility "
                                + "of a player knowing in advance the next card to be dealt due to it "
                                + "being marked.</p>"
                        + "</dd>"
                    + "<dt>"
                        + "<a href='#showdownSection'>The showdown</a>"
                    + "</dt>"
                        + "<dd id='showdownSection' class='MediumSize'>"
                            + "<p>If a player bets and all other players fold, then the "
                                + "remaining player is awarded the pot and is not required to show "
                                + "his hole cards. If two or more players remain after the final "
                                + "betting round, a showdown occurs. On the showdown, each player"
                                + "plays the best poker hand they can make from the seven cards "
                                + "comprising his two hole cards and the five community cards. A "
                                + "player may use both of his own two hole cards, only one, or none "
                                + "at all, to form his final five-card hand. If the five community "
                                + "cards form the player's best hand, then the player is said to be "
                                + "playing the board and can only hope to split the pot, because each "
                                + "other player can also use the same five cards to construct the "
                                + "same hand.</p>"
                            + "<p>If the best hand is shared by more than one player, then the "
                                + "pot is split equally among them, with any extra chips going to the "
                                + "first players after the button in clockwise order. It is common "
                                + "for players to have closely valued, but not identically ranked "
                                + "hands. Nevertheless, one must be careful in determining the best "
                                + "hand; if the hand involves fewer than five cards, (such as two "
                                + "pair or three of a kind), then kickers are used to settle ties. A "
                                + "kicker is a card which is part of the five-card poker hand, but is "
                                + "not used in determining a hand's rank. For instance, in the hand "
                                + "A-A-A-K-Q, the king and queen are kickers. Note that the card's "
                                + "numerical rank is of sole importance; suit values are irrelevant "
                                + "in Hold'em. The last player to bet is the first player to show his "
                                + "hand.</p>"
                            + "</dd>"
                        + "</dl>"
                    + "</div>";
        return returnHtml;
    }
    
    public String HandRankings()
    {
        String returnHtml = new String();
        returnHtml ="<div class='Heading'>"
                + "<h2>Poker Hand Rankings</h2>"
                + "<p>These are the types of hands in poker, listed in order from "
                    + "the strongest to the weakest. Mouseover on a hand to see its name.<p>"
                + "</div>"
                + "<div id='rankingList'>"
                    + "<div class='Hand'>"
                        + "<img alt='Royal Flush' src='res/img/pokerHands/1.png'>"
                        + "<p>Royal Flush</p>"
                    + "</div>"
                    + "<div class='Hand'>"
                        + "<img alt='Straight Flush' src='res/img/pokerHands/2.png'>"
                        + "<p>Straight Flush</p>"
                    + "</div>"
                    + "<div class='Hand'>"
                        + "<img alt='Four Of A Kind' src='res/img/pokerHands/3.png'>"
                        + "<p>Four Of A Kind</p>"
                    + "</div>"
                    + "<div class='Hand'>"                
                        + "<img alt='Full House' src='res/img/pokerHands/4.png'>"
                        + "<p>Full House</p>"
                    + "</div>"
                    + "<div class='Hand'>"
                        + "<img alt='Flush' src='res/img/pokerHands/5.png'>"
                        + "<p>Flush</p>"
                    + "</div>"
                    + "<div class='Hand'>"                
                        + "<img alt='Straight' src='res/img/pokerHands/6.png'>"
                        + "<p>Straight</p>"
                    + "</div>"
                    + "<div class='Hand'>"
                        + "<img alt='Three Of A Kind' src='res/img/pokerHands/7.png'>"
                        + "<p>Three Of A Kind</p>"
                    + "</div>"
                    + "<div class='Hand'>"
                        + "<img alt='Two Pairs' src='res/img/pokerHands/8.png'>"                
                        + "<p>Two Pairs</p>"
                    + "</div>"
                    + "<div class='Hand'>"
                        + "<img alt='One Pair' src='res/img/pokerHands/9.png'>"               
                        + "<p>One Pair</p>"
                    + "</div>"
                    + "<div class='Hand'>"
                        + "<img alt='High Card' src='res/img/pokerHands/10.png'>"
                        + "<p>High Card</p>"
                    + "</div>"
                + "</div>";               
        return returnHtml;
    }
    
    public String AboutUs()
    {
        String returnHtml = new String();
        returnHtml ="<div class='Heading'>"
                + "<h2>Who Are We?</h2>"
                + "</div>"
                + "<div id='content'>"
                    + "<p>We are an organization of friends who play friendly "
                        + "competitive games of Texas Hold'em and are interested in helping to "
                        + "increase the popularity and availability of such tournaments, by "
                        + "providing a tool to organize and help keep track of the outcome of "
                        + "games.</p>"
                    + "<p>We believe that poker is a valid social pastime, and as such "
                        + "can serve as an alternative to other forms of entertainment "
                        + "available to people.</p>"
                    + "<p>By providing a convenient platform which holds the basic "
                        + "rules, quick reference to necessary information for the game, and "
                        + "tools to monitor game outcomes and attending players, our aim is to "
                        + "make organizing Hold'em tournaments more accessible and easy, "
                        + "thereby increasing popular interest in the game.</p>"
                + "</div>"
                + "<div class='contact'>"
                    + "<img src='res/img/emailGold.png' />"
                    + "<a class='email' href='mailto:PokerStats@potato.com'>PokerStats@potato.com</a><br>"
                    + "<img src='res/img/phoneGold.png' />03-6803322<br>"
                    + "<img src='res/img/addressGold.png' />Rabbenu Yeruham St.<br>"
                + "</div>"
                + "<div class='easterEgg' hidden='hidden'>WE ARE THE POTATO MASTERS... YOU "
                    + "ARE NOW UNDER OUR INFLUENCE.... DO NOT RESIST</div>"; 
        return returnHtml;
    }
    
    public String MainPage(Integer i_PlayerID)
    {
    	Player player = Player.getPlayerById(i_PlayerID);
    	String returnHtml = new String();
    	returnHtml += "<!DOCTYPE html>"+
		"<html>"+
		"<head>"+
		"<meta charset='UTF-8'>"+
		"<link rel='stylesheet' type='text/css' href='css/mainPageStyle.css'>"+
		"<link rel='stylesheet' type='text/css' href='css/jquery.dataTables.css'>"+
		"<script type='text/javascript' src='js/jquery-1.9.1.min.js'></script>"+
		"<script type='text/javascript' src='js/jquery.dataTables.min.js'></script>";
		if(player.getJoinStatus().equalsIgnoreCase("Approved"))
		{
			returnHtml+="<script type='text/javascript' src='js/spin.min.js'></script>";
			returnHtml+="<script type='text/javascript' src='js/mainPageScript.js'></script>";
		}
		else
		{
			returnHtml+="<script type='text/javascript' src='js/PandingOrDeclinedScript.js'></script>";
		}
		returnHtml+="<title>PokerStats</title>"+
		"</head>";
    	if(player.getJoinStatus().equalsIgnoreCase("Approved") && !player.isTeamLeader())
    	{
    		returnHtml+="<style type='text/css'>.menu{margin-left: 28%;}</style>";
    	}
    	returnHtml+="<body>";
    	if(player.getJoinStatus().equalsIgnoreCase("Approved"))
    	{	
    		returnHtml+="<div id='LinkSignOut'>"+
	    				"<button id='ButtonSignOut' onclick=\"SignOutClicked()\">Sign Out</button>"+
	        		"</div>";
    	}
    	returnHtml+="<div id='banner'>"+
					"<img src='res/img/logo.png' />"+
				"</div>";
    	if(player.getJoinStatus().equalsIgnoreCase( "Approved"))
    	{
    		returnHtml+="<div class='menu'>"+
					"<ul>"+
						"<li class='menuItem'>"+
							"<button class='ButtonNavigationClicked' id='ButtonProfile' onclick=\"mainPageNavigationButtonClicked('Profile','#ButtonProfile')\">"+
								"<img src='res/img/spades.png' /> Profile"+
								"<img src='res/img/hearts.png' />"+
			                                "</button>"+
						"</li>"+
						"<li class='menuItem'>"+
							"<button class='ButtonNavigationNotClicked' id='ButtonPlayers' onclick=\"mainPageNavigationButtonClicked('Players', '#ButtonPlayers')\">"+
								"<img src='res/img/hearts.png' /> Players"+
								"<img src='res/img/clubs.png' />"+
							"</button>"+
						"</li>"+
						"<li class='menuItem'>"+
							"<button class='ButtonNavigationNotClicked' id='ButtonGames' onclick=\"mainPageNavigationButtonClicked('Games', '#ButtonGames')\">"+
								"<img src='res/img/clubs.png' /> Games"+
								"<img src='res/img/Diamonds.png' />"+
							"</button>"+
						"</li>";
	    	if(player.getJoinStatus().equalsIgnoreCase("Approved") && player.isTeamLeader())
	    	{
						returnHtml+="<li class='menuItem'>"+
							"<button class='ButtonNavigationNotClicked' id='ButtonCreateNewGame' onclick=\"mainPageNavigationButtonClicked('CreateNewGame', '#ButtonCreateNewGame')\">"+
								"<img src='res/img/Diamonds.png' /> Create New Game"+
								"<img src='res/img/spades.png' />"+
							"</button>"+
						"</li>"+
						"<li class='menuItem'>"+
						"<button class='ButtonNavigationNotClicked' id='ButtonJoinRequests' onclick=\"mainPageNavigationButtonClicked('JoinRequests', '#ButtonJoinRequests')\">"+
							"<img src='res/img/clubs.png' /> Members Info"+
							"<img src='res/img/hearts.png' />"+
						"</button>"+
						"</li>";
	    	}
	    	returnHtml+="</ul>"+
				"</div>";
    	}
    	returnHtml+="<div id='DivMainContainer'>";
    	if(!player.getJoinStatus().equalsIgnoreCase("Approved"))
    	{
    		returnHtml += pandingOrDeclinedPage(i_PlayerID,player.getJoinStatus());
    	}
    	returnHtml+="</div>"+
		"</body>"+
		"</html>";
    	
    	return returnHtml;
    }

	private String pandingOrDeclinedPage(Integer i_PlayerID, String i_PlayerStatus)
	{
		Player player = Player.getPlayerById(i_PlayerID);
		Team currentTeam = Team.getTeamById(player.getTeamId());
		String returnHtml = new String();
		returnHtml = "<div id='DivPandingOrDeclined'>";
		returnHtml += "<h1>Your request to join Team \""+currentTeam.getName()+"\"";
			if(i_PlayerStatus.equalsIgnoreCase("Pending"))
			{
				returnHtml+= " has not been approved yet!</h1>" + "<p>Please check back later, or";
			}
			else
			{
				returnHtml+=" was declined, or you were kicked off the team.</h1><p>";
			}
			returnHtml+= " try to join another team.</p><br/>";
			returnHtml+="<button id='ButtonJoinTeam' onClick='JoinTeam()'>Join Team</button>";
			returnHtml+= "<select id='SelectJoinTeam'>";
			for(Team team: Team.getTeamsInSystem())
			{
				returnHtml+= "<option "+((Team.getTeamById(Player.getPlayerById(i_PlayerID).getTeamId()).getName().equalsIgnoreCase(team.getName()))?"selected='selected'":"")+" value='"+team.getId()+"'>"+team.getName()+"</option>";
			}
			returnHtml+= "</select>";
			returnHtml+= "<button id='ButtonTryLaterLogOut' onClick='TryLaterLogOut()'>"+((i_PlayerStatus.equalsIgnoreCase("Panding"))?"Try Later":"Maybe Later")+"</button>";
		returnHtml+= "</div>";
		return returnHtml;
	}
}